﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils
{
    public static class StringExtensions
    {
        public static string RemoveQuotes(this string text)
        {
            if (text.StartsWith("\"") || text.StartsWith("'"))
            {
                text = text.Remove(0, 1);
            }

            if (text.EndsWith("\"") || text.EndsWith("'"))
            {
                text = text.Remove(text.Length - 1);
            }

            return text;
        }

        public static string RemoveSurroundingSlashes(this string text)
        {
            if (text.StartsWith("\\") || text.StartsWith("/"))
            {
                text = text.Remove(0, 1);
            }

            if (text.EndsWith("\\") || text.EndsWith("/"))
            {
                text = text.Remove(text.Length - 1);
            }

            return text;
        }

        public static string RemoveEnd(this string text, int count)
        {
            return text.Remove(text.Length - count);
        }

        public static string Truncate(this string text, int lengthToTruncateTo)
        {
            if (text.Length > lengthToTruncateTo)
            {
                return text.RemoveEnd(text.Length - lengthToTruncateTo);
            }
            else
            {
                return text;
            }
        }

        public static string RemoveStart(this string text, int count)
        {
            return text.Remove(0, count);
        }

        public static string RemoveEnd(this string text, string lengthOfString)
        {
            return text.Remove(text.Length - lengthOfString.Length);
        }

        public static string RemoveStart(this string text, string lengthOfString)
        {
            return text.Remove(0, lengthOfString.Length);
        }
    }
}
